// NonDBVariable.cpp: implementation of the NonDBVariable class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "NonDBVariable.h"
#include "PropertyVisitor.h"
#include "SimpleExpression.h"
#include "ModelObject.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
namespace PropertySystem
{
	UE_IMPLEMENT_DYNAMIC(NonDBVariable, PropertyVariable);
	NonDBVariable::NonDBVariable()
	{
		
	}
	
	NonDBVariable::~NonDBVariable()
	{
		
	}

	void NonDBVariable::InitValue()
	{
		if(GetOwner() == NULL || this->Default().IsEmpty() || m_bIsInitState)
			return;

		m_bIsInitState = TRUE;
		SimpleExpression expr(this->Default(), this->GetOwner()->GetPropertyStack());

		*static_cast<Variable*>(this) = (CString)expr.Caculate();
		m_bIsInitState = FALSE;
	}

	PropertyVariable* NonDBVariable::Clone()
	{
		NonDBVariable* pVariable = new NonDBVariable;
		ASSERT(pVariable);

		this->CopyPropertyData(*pVariable, *this);

		return pVariable;
	}

	BOOL NonDBVariable::Accept(PropertyVisitor& visitor)
	{
		return visitor.Visit(this);
	}
};
